package com.gw.detail.controllor.param;

import com.gw.detail.domain.param.CommonType;
import com.gw.detail.service.param.ICommonTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通用代码类目Controller
 *
 * @author wangbin
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/detail/commonType")
public class CommonTypeController extends BaseController {
    @Autowired
    private ICommonTypeService commonTypeService;

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('detail:commonType:add')")
    @Log(title = "通用代码类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonType commonType) {
        return toAjax(commonTypeService.insertCommune(commonType));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('detail:commonType:remove')")
    @Log(title = "通用代码类目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(commonTypeService.deleteCommuneByIds(ids));
    }


    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('detail:commonType:edit')")
    @Log(title = "通用代码类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonType commonType) {
        return toAjax(commonTypeService.updateCommune(commonType));
    }



    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('detail:commonType:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonType commonType) {
        startPage();
        List<CommonType> list = commonTypeService.selectCommuneList(commonType);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('detail:commonType:export')")
    @Log(title = "通用代码类目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CommonType commonType) {
        List<CommonType> list = commonTypeService.selectCommuneList(commonType);
        ExcelUtil<CommonType> util = new ExcelUtil<CommonType>(CommonType.class);
        return util.exportExcel(list, "行政区数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:commonType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(commonTypeService.selectCommuneById(id));
    }



}
